package runner

import (
	"ckeadm/constants"
	"github.com/sirupsen/logrus"
	"github.com/urfave/cli"
)

var (
	ConfigPathFlag = cli.StringFlag{
		Name:   "f",
		Usage:  "Specify an alternate cluster YAML file",
		Value:  constants.ClusterConfigDefault,
		EnvVar: "CKEADM_CONFIG",
	}

	PrivateKey               = PrivateKeyWithDefault(constants.EmptyString)
	PrivateKeyDefaultRootKey = PrivateKeyWithDefault(constants.RootPrivateKey)

	AnsibleConfigDirFlag = cli.StringFlag{
		Name:   "config-dir",
		Usage:  "Specify a dir for ansible configuration",
		Value:  constants.EmptyString,
		EnvVar: "CKEADM_CONFIG_DIR",
	}

	AnsibleUpgradeImageFlag = cli.StringFlag{
		Name:   "upgrade-image",
		Usage:  "Specify an image for cke cluster upgrade",
		Value:  constants.EmptyString,
		EnvVar: "CKEADM_UPGADE_IMAGE",
	}

	LogLevelFlag = cli.IntFlag{
		Name:   "v",
		Usage:  "number for the log level verbosity",
		Value:  int(logrus.InfoLevel),
		EnvVar: "CKEADM_LOG_LEVEL",
	}

	CacheDirFlag = cli.StringFlag{
		Name:   "cachedir",
		Usage:  "cachedir for install cache from others store",
		Value:  constants.CkeadmLogCacheDir,
		EnvVar: "CKEADM_CACHE_DIR",
	}

	AddressFlag = cli.StringFlag{
		Name:   "address",
		Usage:  "installing nodes address",
		EnvVar: "CKEADM_INSTALL_ADDRESS",
	}

	// only command wait set when --following and -f not set
	ClusterIdFlag = cli.StringFlag{
		Name:   "clusterID",
		Usage:  "clusterId for store info for cluster",
		Value:  constants.ClusterIdDefault,
		EnvVar: "CKEADM_CLUSTER_ID",
	}

	ActionFlag = cli.StringFlag{
		Name:   "action",
		Usage:  "operation of a component",
		Value:  constants.EmptyString,
		EnvVar: "CKEADM_ACTION",
	}

	WatchPortFlag = cli.IntFlag{
		Name:   "port",
		Usage:  "port for wait binding",
		Value:  constants.WaitPort,
		EnvVar: "CKEADM_WAIT_PORT",
	}

	FollowingFlag = cli.BoolFlag{
		Name:   "following",
		Usage:  "use this to following running and show result",
		EnvVar: "CKEADM_FOLLOWING",
	}

	SureButtonFlag = cli.BoolFlag{
		Name:   "y",
		Usage:  `Automatic yes to prompts; assume "yes" as answer to all prompts and run non-interactively.`,
		EnvVar: "CKEADM_RUN_YES",
	}

	ComponentFlag = cli.StringFlag{
		Name:   "component",
		Usage:  `CkeComponent CR string encoded with base64`,
		EnvVar: "CKEADM_COMPONENT",
	}

	ClusterFlag = cli.StringFlag{
		Name:   "cluster",
		Usage:  `CkeCluster CR string encoded with base64`,
		EnvVar: "CKEADM_CLUSTER",
	}

	NodeFlag = cli.StringFlag{
		Name:   "node",
		Usage:  `CkeNode CR string encoded with base64`,
		EnvVar: "CKEADM_NODE",
	}

	NodeNameFlag = cli.StringFlag{
		Name:   "nodeName",
		Usage:  `node name`,
		EnvVar: "CKEADM_NODE_NAME",
	}

	ComponentNameFlag = cli.StringFlag{
		Name:   "name",
		Usage:  `Component Name`,
		EnvVar: "CKEADM_COMPONENT_NAME",
	}

	AddressListFlag = cli.StringFlag{
		Name:   "address-list",
		Usage:  `masters ip addresses list`,
		EnvVar: "CKEADM_ADDRESS_LIST",
	}

	StatusComponentFlag = cli.StringFlag{
		Name:   "c",
		Usage:  `component name`,
		EnvVar: "CKEADM_STATUS_COMPONENT",
	}

	StatusNodeFlag = cli.StringFlag{
		Name:   "n",
		Usage:  `node name`,
		EnvVar: "CKEADM_STATUS_NODE",
	}

	SkipFlag = cli.StringFlag{
		Name:   "skip",
		Usage:  `stage name`,
		EnvVar: "CKEADM_SKIP",
	}

	FromVersionFlag = cli.StringFlag{
		Name:   "fromVersion",
		Usage:  `ckeadm from version`,
		EnvVar: "CKEADM_FROM_VERSION",
	}

	ToVersionFlag = cli.StringFlag{
		Name:   "toVersion",
		Usage:  `ckeadm to version`,
		EnvVar: "CKEADM_TO_VERSION",
	}

	RegistryFlag = cli.StringFlag{
		Name:   "registry",
		Usage:  `ckeadm to version`,
		Value:  constants.RegistryDefault,
		EnvVar: "CKEADM_REGISTRY",
	}
)

func PrivateKeyWithDefault(keyfile string) cli.StringFlag {
	return cli.StringFlag{
		Name:   "private-key",
		Usage:  "Specify a ssh private key file",
		Value:  keyfile,
		EnvVar: "CKEADM_PRIVATE_KEY",
	}
}
